<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java I/O 模型深度解析</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        
        .card-hover {
            transition: all 0.3s ease;
            border: 2px solid transparent;
        }
        
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0, 0, 0, 0.1);
            border-color: #667eea;
        }
        
        .text-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        .feature-icon {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        
        .section-divider {
            height: 2px;
            background: linear-gradient(to right, transparent, #667eea, transparent);
            margin: 3rem 0;
        }
        
        @keyframes fadeInUp {
            from {
                opacity: 0;
                transform: translateY(30px);
            }
            to {
                opacity: 1;
                transform: translateY(0);
            }
        }
        
        .fade-in-up {
            animation: fadeInUp 0.6s ease-out;
        }
        
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            margin-top: -0.2rem;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20 px-6">
        <div class="max-w-6xl mx-auto text-center fade-in-up">
            <h1 class="text-5xl md:text-6xl font-bold mb-6">
                <i class="fas fa-network-wired mr-4"></i>
                Java I/O 模型深度解析
            </h1>
            <p class="text-xl md:text-2xl opacity-90 max-w-3xl mx-auto leading-relaxed">
                从阻塞到异步，探索 Java 网络编程的六大 I/O 模型，掌握高性能应用的核心技术
            </p>
        </div>
    </section>

    <!-- Main Content -->
    <main class="max-w-7xl mx-auto px-6 py-12">
        <!-- Introduction -->
        <section class="bg-white rounded-2xl shadow-xl p-8 mb-12 fade-in-up">
            <p class="text-lg leading-relaxed text-gray-700">
                <span class="drop-cap">在</span>现代软件开发中，I/O 模型的选择直接影响着应用程序的性能和可扩展性。Java 提供了多种 I/O 模型，每种模型都有其独特的特点和适用场景。本文将深入探讨六种主要的 I/O 模型，帮助您在实际开发中做出最佳选择。
            </p>
        </section>

        <!-- Visualization -->
        <section class="bg-white rounded-2xl shadow-xl p-8 mb-12 fade-in-up">
            <h2 class="text-3xl font-bold mb-6 text-center text-gradient">
                <i class="fas fa-sitemap mr-3"></i>I/O 模型关系图
            </h2>
            <div class="mermaid">
                graph TD
                    A[Java I/O 模型] --> B[阻塞 I/O]
                    A --> C[非阻塞 I/O]
                    A --> D[选择器 I/O]
                    A --> E[异步 I/O]
                    A --> F[Reactor 模型]
                    A --> G[Proactor 模型]
                    
                    B --> B1[简单易用]
                    B --> B2[线程阻塞]
                    
                    C --> C1[轮询机制]
                    C --> C2[中等并发]
                    
                    D --> D1[事件驱动]
                    D --> D2[高效资源利用]
                    
                    E --> E1[异步回调]
                    E --> E2[高吞吐量]
                    
                    F --> F1[事件循环]
                    F --> F2[高性能应用]
                    
                    G --> G1[自动化处理]
                    G --> G2[操作系统支持]
                    
                    style A fill:#667eea,stroke:#fff,stroke-width:3px,color:#fff
                    style B fill:#f59e0b,stroke:#fff,stroke-width:2px,color:#fff
                    style C fill:#10b981,stroke:#fff,stroke-width:2px,color:#fff
                    style D fill:#3b82f6,stroke:#fff,stroke-width:2px,color:#fff
                    style E fill:#8b5cf6,stroke:#fff,stroke-width:2px,color:#fff
                    style F fill:#ef4444,stroke:#fff,stroke-width:2px,color:#fff
                    style G fill:#ec4899,stroke:#fff,stroke-width:2px,color:#fff
            </div>
        </section>

        <!-- I/O Models Grid -->
        <div class="grid grid-cols-1 md:grid-cols-2 gap-8 mb-12">
            <!-- 阻塞 I/O -->
            <article class="bg-white rounded-2xl shadow-lg p-8 card-hover fade-in-up">
                <div class="flex items-center mb-6">
                    <div class="w-16 h-16 bg-yellow-100 rounded-full flex items-center justify-center mr-4">
                        <i class="fas fa-pause-circle text-3xl text-yellow-600"></i>
                    </div>
                    <h3 class="text-2xl font-bold">1. 阻塞 I/O</h3>
                </div>
                
                <div class="mb-6">
                    <h4 class="text-lg font-semibold mb-3 text-gray-800">
                        <i class="fas fa-star mr-2 text-yellow-500"></i>特点
                    </h4>
                    <ul class="space-y-2 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                            <span><strong>阻塞行为：</strong>在进行 I/O 操作时（如读取数据），线程会被阻塞，直到操作完成。</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                            <span><strong>简单易用：</strong>编程模型简单，适合处理少量的连接或数据流。</span>
                        </li>
                    </ul>
                </div>
                
                <div class="mb-6">
                    <h4 class="text-lg font-semibold mb-3 text-gray-800">
                        <i class="fas fa-bullseye mr-2 text-blue-500"></i>适用场景
                    </h4>
                    <ul class="space-y-2 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-arrow-right text-blue-500 mt-1 mr-3"></i>
                            <span><strong>简单应用：</strong>适合连接数较少、对性能要求不高的应用场景。</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-arrow-right text-blue-500 mt-1 mr-3"></i>
                            <span><strong>小型服务：</strong>适用于不需要高并发的简单网络服务。</span>
                        </li>
                    </ul>
                </div>
                
                <div class="bg-gray-50 rounded-lg p-4">
                    <h4 class="text-lg font-semibold mb-2 text-gray-800">
                        <i class="fas fa-code mr-2 text-purple-500"></i>示例
                    </h4>
                    <p class="text-gray-700">使用 <code class="bg-gray-200 px-2 py-1 rounded">Socket</code> 和 <code class="bg-gray-200 px-2 py-1 rounded">InputStream</code>/<code class="bg-gray-200 px-2 py-1 rounded">OutputStream</code> 进行数据读取和写入。</p>
                </div>
            </article>

            <!-- 非阻塞 I/O -->
            <article class="bg-white rounded-2xl shadow-lg p-8 card-hover fade-in-up">
                <div class="flex items-center mb-6">
                    <div class="w-16 h-16 bg-green-100 rounded-full flex items-center justify-center mr-4">
                        <i class="fas fa-play-circle text-3xl text-green-600"></i>
                    </div>
                    <h3 class="text-2xl font-bold">2. 非阻塞 I/O</h3>
                </div>
                
                <div class="mb-6">
                    <h4 class="text-lg font-semibold mb-3 text-gray-800">
                        <i class="fas fa-star mr-2 text-yellow-500"></i>特点
                    </h4>
                    <ul class="space-y-2 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                            <span><strong>非阻塞行为：</strong>线程可以在 I/O 操作期间继续执行其他任务，而不需要等待 I/O 完成。</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                            <span><strong>轮询：</strong>通常需要通过轮询机制检查 I/O 操作的完成状态。</span>
                        </li>
                    </ul>
                </div>
                
                <div class="mb-6">
                    <h4 class="text-lg font-semibold mb-3 text-gray-800">
                        <i class="fas fa-bullseye mr-2 text-blue-500"></i>适用场景
                    </h4>
                    <ul class="space-y-2 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-arrow-right text-blue-500 mt-1 mr-3"></i>
                            <span><strong>中等并发：</strong>适用于中等规模的并发连接场景，性能比阻塞 I/O 更高。</span>
                        </li>
                    </ul>
                </div>
                
                <div class="bg-gray-50 rounded-lg p-4">
                    <h4 class="text-lg font-semibold mb-2 text-gray-800">
                        <i class="fas fa-code mr-2 text-purple-500"></i>示例
                    </h4>
                    <p class="text-gray-700">使用 <code class="bg-gray-200 px-2 py-1 rounded">java.nio</code> 包中的 <code class="bg-gray-200 px-2 py-1 rounded">SocketChannel</code> 和 <code class="bg-gray-200 px-2 py-1 rounded">Selector</code> 进行非阻塞 I/O 操作。</p>
                </div>
            </article>

            <!-- 选择器 I/O -->
            <article class="bg-white rounded-2xl shadow-lg p-8 card-hover fade-in-up">
                <div class="flex items-center mb-6">
                    <div class="w-16 h-16 bg-blue-100 rounded-full flex items-center justify-center mr-4">
                        <i class="fas fa-filter text-3xl text-blue-600"></i>
                    </div>
                    <h3 class="text-2xl font-bold">3. 选择器 I/O</h3>
                </div>
                
                <div class="mb-6">
                    <h4 class="text-lg font-semibold mb-3 text-gray-800">
                        <i class="fas fa-star mr-2 text-yellow-500"></i>特点
                    </h4>
                    <ul class="space-y-2 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-green-500 mt-1 mr-3"></i>
                            <span><strong>事件驱动：</strong>通过 <code class="bg-gray-200 px-2 py-1 rounded">Selector</code